package com.schoolai.schoolset.api;

import com.schoolai.schoolset.req.SetNewsREQ;
import com.schoolai.schoolset.service.ISchoolSetNewsService;
import com.schoolai.util.base.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bobby
 * @since 2025-10-30
 */
@RestController
@Slf4j
@Tag(name = "api新闻相关操作", description = "api新闻相关操作")
@RequestMapping("/api/News")
public class ApiSchoolSetNewsController {
    @Autowired
    ISchoolSetNewsService schoolSetNewsService;
    @Operation(summary = "查询新闻")
    @PostMapping("/search")
    @ApiResponses({
            @ApiResponse(responseCode = "20000", description = "操作成功"),
            @ApiResponse(responseCode = "999", description = "错误")
    })
    @Cacheable(cacheNames = "news",key="#root.targetClass.name + '.' + #root.methodName+#req")
    public Result search(@RequestBody SetNewsREQ req) {
        return Result.ok(schoolSetNewsService.queryPage(req));
    }

}
